<template>
  <div class="page">
    <div class="card">
      <div class="card_con balance">
        <div class="b_title"><span>可用积分</span></div>
        <div class="b_number">{{points}}</div>
      </div>
    </div>
    <div class="mycard">
      <div class="weui-cells">
        <div class="weui-cell">
          <div class="weui-cell__bd">积分记录</div>
          <div class="weui-cell__ft"></div>
        </div>
         <template v-if="list.length">
        <div class="weui-cell" v-for="(item,index) in list" :key="index">

          <div class="ilist" >
            <div class="weui-flex">
              <div class="weui-flex__item">{{item.tran_log_id}}</div>
              <div class="weui-flex__item">{{item.points}}</div>
              <div class="i_type">{{item.remark}}</div>
              <div class="i_data">{{item.tran_time}}</div>
            </div>
          </div>
        </div>
        </template>
          <!-- 无数据 -->
        <div class="ilist" v-if="!list.length">
             <span>暂无数据</span>
          </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as appId from "@/utils/util"
export default {
  data () {
    return {
      current: 0,
      points:0,
      pageNo:1,
      pageSize:10,
       list:[],
      result:[]
    }
  },
   onReachBottom () {
    wx.showNavigationBarLoading()
    console.log('pull')
    if(this.result.length){
     this.pageNo++;
    }
    this.getDtail()
    console.log(this.pageNo)
    // wx.stopPullDownRefresh()
   },
  onLoad(options){
    this.points=options.money
  },
  mounted(){
    wx.setNavigationBarTitle({
      title: "积分"
    })
    this.getDetail()
  },
  methods: {
    getDetail(){
       let phone=JSON.parse(wx.getStorageSync('userInfo')).mobileNo;
         let that=this;
          this.$http.request({
            method:"post",
            url:"/v1.0/appletLogin/integralDetails",
            body:{
              "phone":phone,
              "appid":appId.appId,
              "pageNo":that.pageNo,
              "pageSize":that.pageSize
            }
        }).then((data)=>{
          console.log(data)
          if(data.code==0){
             if(!data.result.length){
               wx.stopPullDownRefresh();
            //    wx.showToast({
            //   title: '暂无更多数据',
            //   icon: 'none',
            //   duration: 2000
            // })
            }
                data.result.forEach(a=>{
                  if( a.tran_time){
                    a.tran_time=a.tran_time.split(' ')[0]
                  }

                })

            if (that.pageNo > 1) {
              that.list.push(...data.result)
              console.log(that.list)
            }else{
               that.list=data.result;
            }
          }
        }).catch((err)=>{
           wx.showToast({
              title: '请求失败',
              icon: 'none',
              duration: 2000
            })
        })
    },
    bindViewTap () {
      const url = '../logs/main'
      if (mpvuePlatform === 'wx') {
        mpvue.switchTab({ url })
      } else {
        mpvue.navigateTo({ url })
      }
    }
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style scoped>
.card{
  margin: 0.8em;
  border-radius: 0.3em;
  background: #fff;
  box-shadow: 0px 0px 0.6em #ddd;
}
.card .card_con{
  padding: 0.6em;
}
.balance{
  position: relative;
  text-align: center;
}
.balance .b_title span{
  background:url(../../../static/images/ic_wdjf.png) left center no-repeat;
  background-size: auto 1.4em;
  padding:0.4em 0px 0.4em 1.6em;
  font-size: 0.8em;
  color: #999;
}
.balance .b_number{
  font-size: 1.6em;
  color: #000;
  padding: 0.3em 0;
  font-weight: bold;
}
.ilist{
  font-size: 0.8em;
  width: 100%;
  text-align: center;
  color: #666;
  line-height: 1.8em;
}
.i_type{
  width: 5em;
}
.i_data{
  width: 8.5em;
  color: #999;
}
</style>
